package com.lemon.smartsafety.ui.adapter.safe.data;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.smartsafety.BuildConfig;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.entity.safe.company.CompanyInfo;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.common.StringUtils;

import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/1/27.
 * 企业信息列表项目
 */
public class SafeDataCompanyInfoItem implements AdapterItem<CompanyInfo> {

    private ImageView iconView, imageArrow;
    private TextView mTextTitle, mTextTip;
    private RelativeLayout mMainLayout;


    private RecyclerTClickListener<CompanyInfo> mListener;
    private CompanyInfo                         mData;
    private int                                 mPosition;

    public SafeDataCompanyInfoItem(RecyclerTClickListener<CompanyInfo> recycleItemClickListener) {
        this.mListener = recycleItemClickListener;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.item_icon_title_tip_arrow;
    }

    @Override
    public void bindViews(View root) {
        mMainLayout = (RelativeLayout) root.findViewById(R.id.itemMainLayout);
        iconView = (ImageView) root.findViewById(R.id.imageIcon);
        imageArrow = (ImageView) root.findViewById(R.id.imageArrow);
        imageArrow.setVisibility(View.VISIBLE);
        mTextTitle = (TextView) root.findViewById(R.id.itemText);
        mTextTip = (TextView) root.findViewById(R.id.itemSubText);
    }

    @Override
    public void setViews() {
        mMainLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onItemClick(mData, mPosition);
                }
            }
        });
    }

    @Override
    public void handleData(CompanyInfo companyInfo, int position) {
        mData = companyInfo;
        mPosition = position;
        if (BuildConfig.DEBUG) {
            mTextTitle.setText(position + ">" + StringUtils.nullValue(companyInfo.getCompany_name()));
        }else{
            mTextTitle.setText(StringUtils.nullValue(companyInfo.getCompany_name()));
        }
    }


}
